package com.kui.web;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.kui.entity.Qikan;
import com.kui.entity.Wenxian;
import com.kui.service.QikanService;
import com.kui.service.WenxianService;

public class QikanServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String m = request.getParameter("m");
		if(m == null){
			QikanService qs = new QikanService();
			List<Qikan> qikanlist = qs.findAll();
			request.setAttribute("qikanlist", qikanlist);
			request.getRequestDispatcher("WEB-INF/views/qikan.jsp").forward(request, response);
		}else if("detail".equals(m)){
			String qid = request.getParameter("qid");
			if(qid == null || "".equals(qid)){
				response.sendRedirect("qikan.jspx");
				return;
			}
			
			WenxianService ws = new WenxianService();
			List<Wenxian> wenxianlist = ws.findByQikanId(qid);
			request.setAttribute("wenxianlist", wenxianlist);
			request.getRequestDispatcher("WEB-INF/views/qikan_wenxian.jsp").forward(request, response);
		}else{
			response.sendRedirect("qikan.jspx");
		}
		

	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

	}

}
